﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_ReturnGood : UCBase
{
    public UserControls_ReturnGood()
    {
        Name = "退货申请";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (_Customer == null)
        {
            Response.Redirect("Default.aspx?PN=Login");
        }
        else
        {
            LoadData();
        }
    }

    /// <summary>
    /// 加载数据
    /// </summary>
    private void LoadData()
    {
        long ShopID =_Site.ID;
        this.Page1.FindType = 0;
        this.Page1.Field1 = "";
        this.Page1.Field2 = "";
        this.Page1.Like1 = "";
        this.Page1.Like2 = "";
        Page1.GridID = gvOrder;
        Page1.Condition = "where CustomerID=" + _Site.ID + " and TargetShopID=" + ShopID + "";
        Page1.TableName = "V_BackGoodMaster";
    }

    protected void gvOrder_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //设置表格的样式
         e.Row.Attributes.Add("class", "black12");
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Style.Add("background-image", "url(images/bg_hui_23_2.jpg)");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.BackColor = System.Drawing.Color.FromName("#FFFFFF");

            if (e.Row.Cells[4].Text == "已退款" && e.Row.Cells[3].Text == "换货")
            {
                e.Row.Cells[4].Text = "已发货";
            }
            //对发货按钮的处理
            LinkButton lbSend = (LinkButton)e.Row.FindControl("lbSend");

            if (e.Row.Cells[4].Text == "通过")
            {
                lbSend.Enabled = true;
            }
            else
            {
                lbSend.Enabled = false;
            }

            if (lbSend.Enabled == true && lbSend.Text == "发货")
            {
                lbSend.Attributes.Add("onclick", "return confirm('确定此操作吗？')");
            }

            //对收款按钮的处理
            LinkButton lbReceive = (LinkButton)e.Row.FindControl("lbReceive");

            if (e.Row.Cells[4].Text == "已退款")
            {
                lbReceive.Enabled = true;
            }
            else
            {
                lbReceive.Enabled = false;
            }

            if (lbReceive.Enabled == true && lbReceive.Text == "收款")
            {
                lbReceive.Attributes.Add("onclick", "return confirm('确定此操作吗？')");
            }

            //收货
            LinkButton lbReceiveGood = (LinkButton)e.Row.FindControl("lbReceiveGood");
            if (e.Row.Cells[4].Text == "已发货")
            {
                lbReceiveGood.Enabled = true;
            }
            else
            {
                lbReceiveGood.Enabled = false;
            }
            if (lbReceiveGood.Enabled == true && lbReceiveGood.Text == "收货")
            {
                lbReceiveGood.Attributes.Add("onclick", "return confirm('确定此操作吗？')");
            }
        }
    }

    /// <summary>
    /// 发货(修改退货单状态为1)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvOrder_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Entity.BackGood b = new Entity.BackGood();
        //b.ID = Shove._Convert.StrToLong(gvOrder.DataKeys[e.RowIndex].Value.ToString(), 0);
        //b.Status = 1;
        //BLL.BackGoodBLL.UpdateBackGoodMasterStatus(b);
        
        //Response.Redirect("Default.aspx?PN=member_home&Type=ReturnGood.ascx");
    }

    /// <summary>
    /// 收款(修改退货单状态为6)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvOrder_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Entity.BackGood b = new Entity.BackGood();
        //b.ID = Shove._Convert.StrToLong(gvOrder.DataKeys[e.RowIndex].Value.ToString(), 0);
        //b.Status = 6;
        //BLL.BackGoodBLL.UpdateBackGoodMasterStatus(b);
        //Response.Redirect("Default.aspx?PN=member_home&Type=ReturnGood.ascx");
    }

    protected void gvOrder_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        //Entity.BackGood b = new Entity.BackGood();
        //b.ID = Shove._Convert.StrToLong(gvOrder.DataKeys[e.NewSelectedIndex].Value.ToString(), 0);
        //b.Status = 6;
        //BLL.BackGoodBLL.UpdateBackGoodMasterStatus(b);
        Response.Redirect("Default.aspx?PN=member_home&Type=ReturnGood.ascx");
    }
}
